package aes.gui;

import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JSeparator;
import javax.swing.JButton;

import aes.general.AdminControl;


/**
 * The Class AdminReportsPanel. This panel is an option panel provided
 * for the admin to choose which kind of report he wants to see.
 * Reports about specific teacher or course or maybe student.
 * It's all there.
 */
public class AdminReportsPanel extends JPanel implements ActionListener{

	private static final long serialVersionUID = 1L;
	private JPanel cp; 
	private JLabel l1;
	private JSeparator separator;
	private JRadioButton rdbtnCourseName;
	private JRadioButton rdbtnTeacherId;
	private JRadioButton rdbtnExamNumber;
	private ButtonGroup group;
	private JButton btnNext;
	private JButton btnPrev;
	                             
    private AdminStudentStatsPanel GrdExmid = null;        
	private AdminTeacherStatsPanel GrdTchid = null;     
	private AdminCourseStatsPanel GrdCrsid = null;      

	private int mode ;
	
	/**
	 * Create the panel.
	 * 
	 * @param contentPane
	 *            the content pane
	 */
	public AdminReportsPanel(JPanel contentPane) {
		this.cp = contentPane;
		initialize();
	}
	
	
	/**
	 * Initialize.
	 */
	private void initialize() {
		setLayout(null);
		
		l1 = new JLabel("Reports");
		l1.setBounds(264, 11, 111, 29);
		l1.setToolTipText("");
		l1.setLabelFor(l1);
		l1.setForeground(Color.BLACK);
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		add(l1);//"Grade's Reports under (the room rate
		
		separator = new JSeparator();
		separator.setBounds(10, 43, 620, 2);
		add(separator);
		
		group = new ButtonGroup();
		

	    rdbtnExamNumber = new JRadioButton("Student's Statistics",false);
	    rdbtnExamNumber.setBounds(32, 171, 165, 23);
		rdbtnExamNumber.setActionCommand("Exam number:");
		add(rdbtnExamNumber);
		
		
		rdbtnTeacherId = new JRadioButton("Teacher's Statistics",false);
		rdbtnTeacherId.setBounds(32, 105, 179, 23);
		rdbtnExamNumber.setActionCommand("Teacher ID:");
		add(rdbtnTeacherId);
		
		rdbtnCourseName = new JRadioButton("Course's Statistics",false);
		rdbtnCourseName.setBounds(32, 234, 165, 23);
		rdbtnExamNumber.setActionCommand("Course Name:");
		add(rdbtnCourseName);
		rdbtnExamNumber.setActionCommand("Student ID:");
		
		
		group.add(rdbtnExamNumber);
		group.add(rdbtnTeacherId);
		group.add(rdbtnCourseName);
		
		rdbtnExamNumber.addActionListener(this);
		rdbtnTeacherId.addActionListener(this);
		rdbtnCourseName.addActionListener(this);
			
		  btnNext = new JButton("Next");
		  btnNext.setBounds(335, 374, 89, 23);
			btnNext.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (group.getSelection()==null)
						{
						JOptionPane.showMessageDialog(null, "Error,No Selected Option", "Error",
							JOptionPane.ERROR_MESSAGE);
						return;
						}
					
					else if (mode==1)
						{
						group.clearSelection();
						AdminControl.getTeacherId();
						GrdTchid = new AdminTeacherStatsPanel(cp);
					    cp.add(GrdTchid, "AdminGradeTeacherPanel");
					    CardLayout cl = (CardLayout) (cp.getLayout());
						cl.show(cp, "AdminGradeTeacherPanel");  
						
						}
					else if (mode==2)
						{
							group.clearSelection();
							AdminControl.getCourseId();
							GrdCrsid=new AdminCourseStatsPanel(cp);
							cp.add(GrdCrsid, "AdminGradeCoursePanel");
							CardLayout cl = (CardLayout) (cp.getLayout());
							cl.show(cp, "AdminGradeCoursePanel"); 
						
						}
				
					else if (mode==3)
						{
						group.clearSelection();
						AdminControl.getStudentsId();
						GrdExmid= new AdminStudentStatsPanel(cp);//will must to choose exam
						cp.add(GrdExmid, "AdminGradeExamPanel");
					     CardLayout cl = (CardLayout) (cp.getLayout());
						cl.show(cp, "AdminGradeExamPanel"); 
						}
				}
			});
			this.add(btnNext);	
			
			
			btnPrev = new JButton("Back");
			btnPrev.setBounds(189, 374, 89, 23);
			add(btnPrev);
			btnPrev.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					CardLayout cl = (CardLayout) (cp.getLayout());
					cl.show(cp, "AdminMain");	
				}
			});
			add(btnPrev);
			
	}
	
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
	
		if(e.getSource()==rdbtnTeacherId)
		  {
				mode=1;   				    	
		  }
		
		if(e.getSource()==rdbtnCourseName)
		   {
				mode=2;
		  
			}
		if(e.getSource()==rdbtnExamNumber)
		   {
				mode=3;
		
			}	
	}
}
			
		
			
			
		    
		  
					
			
			
		
	
	

